import { LOAD_USER,UP_USER,SET_USER,SET_SAGALIST,ADD_SAGALISTITEM,DELETE_SAGALISTITEM } from "../constants";
import defaultState from '../state/user';
export default (state=defaultState,action)=>{
    console.log(action);
    switch(action.type){
        case LOAD_USER:
            return {
                ...state,
                currentUser:action.payload
            }
            break;
        case UP_USER:
            return {
                ...state,
                currentUser:action.payload
            }
            break;
        case SET_USER:
            return {
                ...state,
                currentUser:action.payload
            }
            break;
        case SET_SAGALIST:
            return {
                ...state,
                sagaList:action.payload
            }
            break;
        case ADD_SAGALISTITEM:
            state.sagaList = state.sagaList.concat(action.payload);
            return{
                ...state,
                sagaList:state.sagaList
            }
            break;
        case DELETE_SAGALISTITEM:
            let start = action.payload;
            state.sagaList.splice(start,1);
            return {
                ...state,
                sagaList:[...state.sagaList]
            };
            break;
        default:
            return {
                ...state
            }
    }
}